module.exports = (api) => {
  // 单测里使用，现在暂时没有用到
  if (api.env('test')) {
    return {
      presets: ['@babel/preset-typescript', '@babel/react', ['@babel/env', { targets: '> 1%, ie >= 10' }]],
      babelrcRoots: ['.'],
      plugins: [
        // compat for babel6 preset "stage-0"
        '@babel/plugin-proposal-export-default-from',
        '@babel/plugin-proposal-optional-chaining',
        // ["@babel/plugin-proposal-class-properties", { loose: false }],

        // ["module-resolver", {
        //     "cwd": "packagejson",
        //     "root": ["."],
        //     "alias": {
        //         "kaf": "./src",
        //         "kaf-core": "./src"
        //     }
        // }],

        [
          '@babel/plugin-transform-runtime',
          {
            helpers: false,
            regenerator: true,
          },
        ],

        ['@babel/plugin-proposal-decorators', { legacy: true }],
        ['@babel/plugin-proposal-class-properties', { loose: true }],

        [
          'import',
          {
            libraryName: 'antd',
            libraryDirectory: 'es',
            style: 'css',
          },
        ],

        [
          'react-css-modules',
          {
            filetypes: {
              '.scss': {
                syntax: 'postcss-scss',
              },
            },
            generateScopedName: '[folder]-[local]_[hash:hex:5]',
          },
        ],
      ],
    };
  }
  return {
    presets: ['@babel/react', ['@babel/env', { targets: '> 1%, ie >= 10' }]],
    babelrcRoots: ['.'],
    plugins: [
      // compat for babel6 preset "stage-0"
      '@babel/plugin-proposal-export-default-from',
      ['@babel/plugin-proposal-class-properties', { loose: false }],

      [
        'module-resolver',
        {
          cwd: 'packagejson',
          root: ['.'],
          alias: {
            kaf: './src',
            'kaf-core': './src',
          },
        },
      ],

      [
        '@babel/plugin-transform-runtime',
        {
          helpers: false,
          regenerator: true,
        },
      ],

      [
        'import',
        {
          libraryName: 'antd',
          libraryDirectory: 'es',
          style: 'css',
        },
      ],

      [
        'react-css-modules',
        {
          filetypes: {
            '.scss': {
              syntax: 'postcss-scss',
            },
          },
          generateScopedName: '[folder]-[local]_[hash:hex:5]',
        },
      ],
    ],
  };
};
